<?php
class GoodsWidget extends CWidget
{
    public $cart_num = 0;
    public $name = '';
    public function init()
    {
        parent::init();
    }
    public function run()
    {
        
        $name= $this->name;
        $cart_count = 0;
        $cart_goods_count = 0;
        if (!Yii::app()->user->isGuest) {
            $filter['user_id'] = Yii::app()->user->getId();
            $data = Cart::model()->ListByAttr($filter);
            if (!empty($data['data'])) {
                $cart_goods_count = $data['goods_count'];//只计算商品的种类数量
                $cart_count =  $data['total_count'];//包含商品的 购物车里的数量
            }
        }
        $this->render('goods',compact('cart_count','cart_goods_count','name'));
    }
}
?>
